package org.beetl.sql.core.db;

import java.lang.annotation.Annotation;
import java.util.List;

import org.beetl.sql.annotation.entity.AssignID;
import org.beetl.sql.annotation.entity.SeqID;
import org.beetl.sql.clazz.kit.BeanKit;
import org.beetl.sql.core.ConnectionSource;
import org.beetl.sql.core.meta.LegacySchemaMetadataManager;
import org.beetl.sql.core.meta.MetadataManager;
import org.beetl.sql.core.meta.SchemaMetadataManager;

public class LegacyOracleStyle extends OracleStyle{
	
	@Override
	public int getIdType(Class c, String idProperty) {
		List<Annotation> ans = BeanKit.getAllAnnotation(c, idProperty);
		int idType = DBType.ID_ASSIGN; // 默认是自增长

        for (Annotation an : ans) {
            if (an instanceof SeqID) {
                idType = DBType.ID_SEQ;
                //seq 总是优先
                break;
            } else if (an instanceof AssignID) {
                idType = DBType.ID_ASSIGN;
//                break;
            } else if(an instanceof org.beetl.sql.core.annotatoin.AssignID) {
				idType = DBType.ID_ASSIGN;
			} else if(an instanceof org.beetl.sql.core.annotatoin.SeqID) {
				idType = DBType.ID_SEQ;
				break;
			}
        }

        return idType;
	}
	
	@Override
	public MetadataManager initMetadataManager(ConnectionSource cs) {
		metadataManager = new LegacySchemaMetadataManager(cs, this) {
			protected String[] getScope(String catalog,String schema){
				return new String[] { "TABLE","VIEW" ,"SYNONYM"};
			}
		};
		return metadataManager;
	}

	@Override
	public MetadataManager initMetadataManager(ConnectionSource cs, String defaultSchema, String defalutCatalog) {
		metadataManager = new LegacySchemaMetadataManager(cs, defaultSchema, defalutCatalog, this);
		return metadataManager;
	}

}
